package com.chwn.harulib.base;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chwn.harulib.R;
import com.umeng.analytics.MobclickAgent;


/**
 * Created by Myshikin on 2017/3/14.
 */
public abstract class BaseFragment extends Fragment {

    protected Context mActivity;
    protected View    mRootView;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mActivity = getActivity();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = LayoutInflater.from(mActivity).inflate(getRootViewLayout(), container, false);
        initData();
        initView();
        initListener();
        return mRootView;
    }

    /**
     * 获取布局ID
     * @return
     */
    protected abstract int getRootViewLayout();

    /**
     * 初始化数据--其他页面传来的、页面所需的静态数据
     */
    protected void initData() {

    }

    /**
     * 初始化布局---
     */
    protected void initView() {

    }

    /**
     * 初始化监听
     */
    protected void initListener() {

    }

    /**
     * 初始化页面所需的动态数据--网络、本地
     */
    protected void loadData() {

    }

    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(getClass().getSimpleName());
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(getClass().getSimpleName());
    }

    @Override
    public void startActivity(Intent intent) {
        super.startActivity(intent);
        getActivity().overridePendingTransition(R.anim.next_in, R.anim.next_out);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

    }
}
